package com.example.demo.common;

import com.example.demo.entity.Userinfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description: 与当前登录用户相关的操作
 */
public class UserSessionUtils {

    public static Userinfo getUserBySession(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if(session != null &&
                session.getAttribute(AppConstant.USER_SESSION_KEY) != null) {
            // 说明用户已正常登录
            return (Userinfo) session.getAttribute(AppConstant.USER_SESSION_KEY);
        }
        return null;
    }
}
